﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;

namespace Banking.Nhân_viên
{
    public partial class frmTaoTKThe : Form
    {
        List<LoaiThe> _loaiThe;
        List<LoaiTaiKhoan> _loaiTK;
        List<LoaiTien> _loaiTien;
        int _maTKC;
        int _maKH;
        public frmTaoTKThe(int maKH)
        {
            InitializeComponent();
            _maKH = maKH;
            _maTKC = TaiKhoanChinhDA.GetByMaKH(maKH);
            _loaiThe = LoaiTheDA.GetALL();
            _loaiTK = LoaiTaiKhoanDA.GetAllTKThe();
            _loaiTien = LoaiTienDA.GetALL();
            LoadForm();
        }
        private void LoadForm()
        {
            txtMaTKC.Text = _maTKC.ToString();
            foreach (LoaiThe loai in _loaiThe)
                cmbLoaiThe.Items.Add(loai.TenLoai);
            foreach (LoaiTaiKhoan loai in _loaiTK)
                cmbLoaiTK.Items.Add(loai.TenTK);
            foreach (LoaiTien loai in _loaiTien)
                cmbLoaiTien.Items.Add(loai.TenTien);
        }

        private void btnTao_Click(object sender, EventArgs e)
        {
            TaiKhoanThe tk = new TaiKhoanThe();
            tk.MaTKChinh = _maTKC;
            tk.SoDu = float.Parse(txtSoTien.Text);
            tk.LaiSuat = float.Parse(txtLaiSuat.Text);
            tk.MaLoaiThe=_loaiThe[cmbLoaiThe.SelectedIndex].MaLoai;
            tk.MaLoaiTK = _loaiTK[cmbLoaiTK.SelectedIndex].MaLoaiTK;
            tk.MaLoaiTien = _loaiTien[cmbLoaiTien.SelectedIndex].MaLoaiTien;
            tk.LockFlg = 0;
            tk.DelFlg = 0;
            System.Random ran = new Random();
            string mapin = ran.Next(100000, 999999).ToString();

            DataTable dt = TaiKhoanTheDA.TaoTKThe(tk, _maKH, mapin);
            txtMaTKThe.Text = dt.Rows[0]["Column1"].ToString();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}

